package servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DB.DoSelect;
import entity.admin;



public class loginservlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public loginservlet() {
        super();
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		
		boolean flag = false;
		
		String name = request.getParameter("name");
		String password = request.getParameter("password");
		
		admin a = new admin();
		a.setName(name);
		a.setPassword(password);
		
		DoSelect doselect = new DoSelect();
		List<admin> list = doselect.findAll();
		
		for(admin a1:list)
		{
			if(a1.compareTo(a)==0)
			{
				flag = true;
			}else{
				flag = false;
			}
		}
		
		if(flag)
		{
			response.sendRedirect("showStudent.jsp");
		}else{
			response.sendRedirect("failure.jsp");
		}
		
	}

}
